﻿using ClusterAwareAdmin;
using ClusterAwareProperties;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace ClusterAwareAdminTest
{


    /// <summary>
    ///This is a test class for NodeAdminTest and is intended
    ///to contain all NodeAdminTest Unit Tests
    ///</summary>
    [TestClass]
    public class NodeAdminTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        private static ClusterManagerAdmin _manager;

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize]
        public static void ClassTestInitialize(TestContext testContext)
        {
        }
        //
        //Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup]
        public static void ClassTestCleanup()
        {
        }
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize]
        public void Initialize()
        {
            _manager = new ClusterManagerAdmin
            {
                Username = SharedConsts.User,
                Password = SharedConsts.Pwd,
                Domain = SharedConsts.Domain,
                Machine = SharedConsts.Machine,
                CacheInstances = false
            };
            _manager.Connect();
        }
        //
        //Use TestCleanup to run code after each test has run
        [TestCleanup]
        public void Cleanup()
        {
            _manager.Dispose();
        }

        #endregion

        /// <summary>
        ///A test for Resume
        ///</summary>
        [TestMethod]
        public void PauseResumeTest()
        {
            if (_manager.OperationSystem == WindowsOperationSystem.Windows2003 || _manager.OperationSystem == WindowsOperationSystem.Windows2003R2)
            {
                Assert.Inconclusive("Windows 2003 not suport Method Pause/Resume");
            }
            _manager.CacheInstances = true;
            var target = new NodeAdmin(_manager);
            foreach (var node in target.GetNodes().Select(n => n.Name).ToArray())
            {
                target.Pause(node);
                target.Resume(node);
            }
            _manager.CacheInstances = false;
            foreach (var node in target.GetNodes().Select(n => n.Name).ToArray())
            {
                target.Pause(node);
                target.Resume(node);
            }
            ClassTestInitialize(TestContext);
        }

        /// <summary>
        ///A test for NodeAdmin Constructor
        ///</summary>
        [TestMethod]
        public void NodeAdminConstructorTest()
        {
            new NodeAdmin(_manager);
        }
    }
}
